package logic

import (
	"context"
	"three-sxp/userrpc/userrpcclient"

	"three-sxp/api/internal/svc"
	"three-sxp/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AuthLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthLogic {
	return &AuthLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AuthLogic) Auth(req *types.AuthRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.UserRpc.Auth(l.ctx, &userrpcclient.AuthRequest{
		Name:   req.Name,
		IdCard: req.IdCard,
		UserId: int64(req.UserId),
	})
	if res.Code != 200 {
		return &types.Response{
			Code: int(res.Code),
			Msg:  res.Msg,
		}, nil
	}
	return &types.Response{
		Code: int(res.Code),
		Msg:  res.Msg,
	}, nil
}
